package com.lzsoft.IO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Database
{
  public String driverName;
  public String serverName;
  public String userId;
  public String password;
  public String databaseName;
  private Connection conn;

  public Database(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5)
  {
    this.driverName = paramString1;
    this.serverName = paramString2;
    this.userId = paramString3;
    this.password = paramString4;
    this.databaseName = paramString5;
  }

  public String getConnectionString()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("jdbc:sqlserver://").append(this.serverName).append(";").append("databaseName=").append(this.databaseName);
    return localStringBuffer.toString();
  }

  public ResultSet getResultSet(String paramString)
  {
    try
    {
      this.conn = getConnection();
      Statement localStatement = this.conn.createStatement();
      ResultSet localResultSet = localStatement.executeQuery(paramString);
      return localResultSet;
    }
    catch (SQLException localSQLException)
    {
    }
    return null;
  }

  public void close()
    throws SQLException
  {
    if ((this.conn != null) && (!this.conn.isClosed()))
      this.conn.close();
  }

  public Connection getConnection()
  {
    try
    {
      if (this.conn == null)
      {
        Class.forName(this.driverName).newInstance();
        this.conn = DriverManager.getConnection(getConnectionString(), this.userId, this.password);
      }
    }
    catch (InstantiationException localInstantiationException)
    {
    }
    catch (IllegalAccessException localIllegalAccessException)
    {
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
    }
    catch (SQLException localSQLException)
    {
      localSQLException.printStackTrace();
    }
    return this.conn;
  }

  public Statement getStatement()
    throws SQLException
  {
    return this.conn.createStatement();
  }
}